/**  
 * @Title: LogUtil.java
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-11-02 14:17:12 
 */  
package com.fsxgt.datagrid.core.utils;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import ch.qos.logback.classic.Logger;

/**  
 * @ClassName: LogUtil
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2023-11-02 14:17:12 
*/
public class LogHelpper {
	
	public static String path=null;
	
	private static Logger logger=(Logger) LoggerFactory.getLogger(LogHelpper.class);


	
	public static String makeLogFileName(Date logDate, String logId) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");	
		
		return sdf.format(logDate).concat(File.separator).concat(logId)
				.concat(".log");
	}
	
	/**
	 * read log data
	 * @param logFile
	 * @return log line content
	 * @throws IOException 
	 */
	public static List readLines(Date logDate, String logId) throws IOException{
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");	
		String filePath=path.concat(File.separator).concat(makeLogFileName(logDate,logId));

				
		File logFilePath = new File(filePath);
		

		return  FileUtils.readLines(logFilePath, "utf-8");
		
	}
	
	public static void setLogFileName(String logFileName){
		MDC.put("logFileName", logFileName);
	}
	public static String getLogFileName(){
		return MDC.get("logFileName").toString();
	}
	
	public static void clearLogFileName(){
		MDC.clear();
	}
	
	
	
}
